package com.mercury.design.staregy.func;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

/**
 * @author mercury
 */
@Component
public class FunctionalStrategyFactory{


    /**
     * 设计该Map的时候key就是业务方法的入参数据类型，value就是业务方法的出参数据类型
     */
    private static final ConcurrentHashMap<String, Function<Long, String>> FUNCTION_MAP = new ConcurrentHashMap<>(2);


    public static final String ORDER_KEY = "order_key";

    public static final String PRODUCT_KEY = "product_key";


    @PostConstruct
    private void init() {
        FUNCTION_MAP.put(ORDER_KEY, this::order);
        FUNCTION_MAP.put(PRODUCT_KEY, this::product);
    }

    private String product(Long aLong) {

        return null;
    }

    private String order(Long aLong) {
        return null;
    }


    /**
     * 执行业务
     *
     * @param key           约定好的key
     * @param channelCodeId 渠道id
     * @return 结果
     */
    public void execute(String key, Long channelCodeId) {
        Function<Long, String> grant = FUNCTION_MAP.get(key);
        grant.apply(channelCodeId);
    }

}
